package com.shishuo.cms.action.admin;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shishuo.cms.entity.GoodsClassify;
import com.shishuo.cms.entity.vo.JsonVo;

@Controller
@RequestMapping("/admin/goodsClassify")
public class AdminGoodsClassifyAction extends AdminBaseAction{
	
	
	
	@RequestMapping(value = "/add.htm", method = RequestMethod.GET)
	public String addUser(ModelMap modelMap) {
		return "system/goodsClassify/add";
	}
	
	@ResponseBody
	@RequestMapping(value = "/addNew.json", method = RequestMethod.POST)
	public JsonVo<String> addNewGoodsClassify(
			@RequestParam(value = "goodsClassifyName") String goodsClassifyName,
			@RequestParam(value = "categoryOrderNum") Integer categoryOrderNum,
			@RequestParam(value = "categoryIsRecommend") Byte categoryIsRecommend,HttpServletRequest request) {
		JsonVo<String> json = new JsonVo<String>();
		try {
			if (goodsClassifyName.equals("")) {
				json.getErrors().put("goodsClassifyName", "种类名称不能为空");
			}
			// 检测校验结果
			validate(json);
			GoodsClassify goodsClassify=new GoodsClassify();
			goodsClassify.setCategoryName(goodsClassifyName);
			goodsClassify.setCategoryOrderNum(categoryOrderNum);
			goodsClassify.setCreateUserId(this.getAdmin(request).getAdminId());
			goodsClassify.setCategoryIsRecommend(categoryIsRecommend);
			goodsClassifyService.addGoodsClassify(goodsClassify);
			json.setResult(true);
		} catch (Exception e) {
			json.setResult(false);
			json.setMsg(e.getMessage());
		}
		return json;
	}
}
